home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / sat / satra10.arc / NASA2KEP.C next >
C/C++ Source or Header  |  1988-07-11  |  2KB  |  79 lines

  1. /* nasa.c   convert file of NASA keplerians to AMSAT format
  2.  7/12/87  Robert W. Berger N3EMO            */
  3.      
  4. #include <stdio.h>
  5.      
  6. main()
  7. {   char SatName[100],line1[100],line2[100];
  8.     FILE *InFile,*OutFile;
  9.     int LineNum;
  10.     unsigned long SatNum,ElementSet,EpochRev;    /* was int ! */
  11.     double EpochDay,DecayRate,Inclination,RAAN,Eccentricity;
  12.     double ArgPerigee,MeanAnomaly,MeanMotion;
  13.      
  14.     if ((InFile = fopen("nasa.dat","r")) == 0)
  15.         {
  16.     printf("\"nasa.dat\" not found\n");
  17.     exit(-1);
  18.     }
  19.      
  20.     if ((OutFile = fopen("kepler.dat","w")) == 0)
  21.         {
  22.     printf("Can't write \"kepler.dat\"\n");
  23.     exit(-1);
  24.     }
  25.      
  26.      
  27.     while (fgets(SatName,100,InFile))
  28.     {
  29.     printf("%s",SatName);
  30.     fgets(line1,100,InFile);
  31.     fgets(line2,100,InFile);
  32.      
  33.         sscanf(line1,"%1d",&LineNum);
  34.       if (LineNum != 1)
  35.         {
  36.         printf("Line 1 not present for satellite %s",SatName);
  37.         exit(-1);
  38.         }
  39.         sscanf(line2,"%1d",&LineNum);
  40.       if (LineNum != 2)
  41.         {
  42.         printf("Line 2 not present for satellite %s",SatName);
  43.         exit(-1);
  44.         }
  45.      
  46.     sscanf(line1,"%*2c%5ld%*11c%14lf%11lf%*21c%5ld",
  47.         &SatNum,&EpochDay,&DecayRate,&ElementSet);
  48.      
  49.     ElementSet /= 10;   /* strip off checksum */
  50.      
  51.     sscanf(line2,"%*8c%8lf%8lf%7lf%8lf%8lf%11lf%6ld",
  52.        &Inclination,&RAAN,&Eccentricity,&ArgPerigee,&MeanAnomaly,
  53.        &MeanMotion,&EpochRev);
  54.     EpochRev /= 10;   /* strip off checksum */
  55.     Eccentricity *= 1E-7;
  56.      
  57.      
  58.     fprintf(OutFile,"Satellite:      %s",SatName);
  59.     fprintf(OutFile,"Catalog number: %ld\n",SatNum);
  60.     fprintf(OutFile,"Epoch time:     %14.8lf\n",EpochDay);
  61.     fprintf(OutFile,"Element set:    %ld\n",ElementSet);
  62.     fprintf(OutFile,"Inclination:    %lf deg\n",Inclination);
  63.     fprintf(OutFile,"RA of node:     %lf deg\n",RAAN);
  64.     fprintf(OutFile,"Eccentricity:   %lf\n",Eccentricity);
  65.     fprintf(OutFile,"Arg of perigee: %lf deg\n",ArgPerigee);
  66.     fprintf(OutFile,"Mean anomaly:   %lf deg\n",MeanAnomaly);
  67.     fprintf(OutFile,"Mean motion:    %-12.8lf rev/day\n",MeanMotion);
  68.     fprintf(OutFile,"Decay rate:     %11.8le rev/day^2\n",DecayRate);
  69.     fprintf(OutFile,"Epoch rev:      %ld\n",EpochRev);
  70.     fprintf(OutFile,"\n");
  71.     }
  72.      
  73.     fclose(InFile);
  74.     fclose(OutFile);
  75.      
  76. }
  77.  
  78.  
  79.